package common;

import java.awt.Graphics2D;
import java.awt.Stroke;
import java.awt.geom.Arc2D;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;

public class ArcEdge extends LineEdge {

	private double radius;
	private boolean side;

	public ArcEdge() {
		lineStyle = LineStyle.SOLID;
		radius = 0;
		side = true;

	}

	@Override
	public void draw(Graphics2D g2) {
		Stroke oldStroke = g2.getStroke();
		g2.setStroke(lineStyle.getStroke());
		
		Point2D p1 = new Point2D.Double(start.getBounds().getCenterX(),
				start.getBounds().getCenterY());
		Point2D p2 = new Point2D.Double(end.getBounds().getCenterX(),
				end.getBounds().getCenterY());
		
		Point2D mid = new Point2D.Double((p1.getX() + p2.getX())/2, (p1.getY() + p2.getY())/2);
	    double midDist = p1.distance(mid);
	    if (radius < midDist) radius = midDist;
	    if (radius > midDist * 2) radius = midDist * 2;

		g2.draw(getConnectionArc(radius, side));
		g2.setStroke(oldStroke);
	}

	@Override
	public boolean contains(Point2D aPoint) {
	    int ind = getConnectionLine().relativeCCW(aPoint);
	    int sideInd = side?-1:1;
	    Arc2D arc = getConnectionArc(radius, side);
	    Point2D center = new Point2D.Double(arc.getCenterX(), arc.getCenterY());
	    
		return aPoint.distance(center) < radius && getConnectionLine().relativeCCW(aPoint) == sideInd;
	}

	public double getRadius() {
		return radius;
	}

	public void setRadius(double r) {
		radius = r;
	}
	
	public boolean getSide() {
		return side;
	}

	public void setSide(boolean b) {
		side = b;
	}
	
	

}
